﻿namespace ColorWheel.Silverlight.Slider.Demo
{
    using System;
    using System.ComponentModel;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media;
    using ColorWheel.Core;


    public partial class MainPage : UserControl, INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler        PropertyChanged;
        private PaletteColor                            m_color;

    
        public MainPage()
        {
            InitializeComponent();

            m_color = new PaletteColor();
            m_color.Name = "TheColor";
            m_color.DoubleColor = Colors.Orange.Double();

            this.DataContext = this;
        }

        public PaletteColor CurrentColor
        {
            get
            {
                return m_color;
            }

            set
            {
                m_color = value;
                FirePropertyChanged("CurrentColor");
            }
        }

        private void FirePropertyChanged(
            string name
        )
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(name));
            }
        }

        private void Button_Click_1(
            object sender,
            RoutedEventArgs e
        )
        {
            var color = new PaletteColor();
            color.Name = "TheColor";
            color.DoubleColor = RandomColor().Double();

            CurrentColor = color;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            CurrentColor.DoubleColor = RandomColor().Double();
        }

        private Color RandomColor(
        )
        {
            Color c = new Color();
            Random r = new Random(DateTime.Now.Millisecond);

            c.A = 255;
            c.B = (byte)r.Next(255);
            c.G = (byte)r.Next(255);
            c.R = (byte)r.Next(255);

            return c;
        }
    }
}
